package com.fudan.backend.dao;

import com.fudan.backend.handler.IdTypeHandler;
import com.fudan.backend.handler.ListTypeHandler;
import com.fudan.backend.pojo.StoreOpenRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StoreOpenRequestDao {

    @Results(id = "storeOpenRequestMap", value = {
            @Result(column = "store_open_request_id", property = "storeOpenRequestId", typeHandler = IdTypeHandler.class),
            @Result(column = "initiate_time", property = "initiateTime"),
            @Result(column = "process_time", property = "processTime"),
            @Result(column = "user_id", property = "userId", typeHandler = IdTypeHandler.class),
            @Result(column = "store_name", property = "storeName"),
            @Result(column = "category", property = "category", typeHandler = ListTypeHandler.class),
            @Result(column = "id_card_number", property = "idCardNumber"),
            @Result(column = "store_profile", property = "storeProfile"),
            @Result(column = "filing_address", property = "filingAddress"),
            @Result(column = "registered_capital", property = "registeredCapital"),
            @Result(column = "pictures", property = "pictures", typeHandler = ListTypeHandler.class),
            @Result(column = "status", property = "status"),
            @Result(column = "info", property = "info"),
    })
    @Select("select * from t_store_open_request")
    List<StoreOpenRequest> selectAllStoreOpenRequest();

    @ResultMap("storeOpenRequestMap")
    @Select("select * from t_store_open_request where store_open_request_id = #{storeOpenRequestId}")
    StoreOpenRequest selectStoreOpenRequestByStoreOpenRequestId(String storeOpenRequestId);

    @ResultMap("storeOpenRequestMap")
    @Select("select * from t_store_open_request where user_id = #{userId}")
    List<StoreOpenRequest> selectAllStoreOpenRequestByUserId(String userId);

    @Insert("insert into t_store_open_request values " +
            "(#{storeOpenRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, #{initiateTime}, #{processTime}, " +
            "#{userId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, #{storeName}, " +
            "#{category, typeHandler=com.fudan.backend.handler.ListTypeHandler}, #{idCardNumber}, #{storeProfile}, " +
            "#{filingAddress}, #{registeredCapital}, #{pictures, typeHandler=com.fudan.backend.handler.ListTypeHandler}, " +
            "#{status}, #{info})")
    int insertStoreOpenRequest(StoreOpenRequest storeOpenRequest);

    @Update("update t_store_open_request set " +
            "initiate_time = #{initiateTime}, process_time = #{processTime}, " +
            "user_id = #{userId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, store_name = #{storeName}, " +
            "category = #{category, typeHandler=com.fudan.backend.handler.ListTypeHandler}, id_card_number = #{idCardNumber}, " +
            "store_profile = #{storeProfile}, filing_address = #{filingAddress}, registered_capital = #{registeredCapital}, " +
            "pictures = #{pictures, typeHandler=com.fudan.backend.handler.ListTypeHandler}, status = #{status}, info = #{info} " +
            "where store_open_request_id = #{storeOpenRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}")
    int updateStoreOpenRequest(StoreOpenRequest storeOpenRequest);

}
